<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h5 class="modal-title">输入量</h5>
</div>

<div class="main-body">

    <div>
        <div>
            <div>
                <label>参数测点</label>
                <table id="dataTable_parameterOut" data-url="/project/arithmeticManage/Parameter_data"
                       data-page-list=[]
                       data-striped="true" data-pagination="true" data-page-size="15" data-cache="false">

                </table>
            </div>
        </div>
    </div>

</div>
<div class="modal-footer" style="text-align:center">

    <button type="button" class="btn btn-primary" onclick="chooseOutParameter()">确定</button>
</div>

<script>

    //table字段
    var dataFormat = [{
        checkbox: true
    }, {
        field: 'code',
        title: '编号',
        align: 'center'
    }, {
        field: 'name',
        title: '名称',
        align: 'center'
    }, {
        field: 'esName',
        title: '诊断代码',
        align: 'center'
    },{
        field: 'objName',
        title: '对象',
        align: 'center',
        formatter: function (value, row, index) {
            if (value == 1) {
                return '项目';
            }
            if (value == 2) {
                return '变流器';
            }
            if (value == 3) {
                return '电池包';
            }
            if (value == 4) {
                return '电池模组';
            }
            if (value == 5) {
                return '电池单体';
            }
            if (value == 6) {
                return '平台';
            }
        }
    }];

    getTableConditon(dataFormat, "dataTable_parameterOut");

    function getTableConditon(dataFormat, id) {
        $("#" + id).bootstrapTable({
            method: "get",
            sidePagination: "server",
            dataType: "json",
            queryParams: function queryParams(params) {   //设置查询参数
                var param = {
                    pageNum: params.offset / params.limit
                };
                $(".search-data").each(function () {
                    var key = $(this).attr("name");
                    var val = $(this).val();
                    if (val) {
                        param[key] = val;
                    }
                });
                console.log(param);
                return param;
            },
            columns: dataFormat
        });
    }

    function chooseOutParameter() {

        var getSelectRows = $("#dataTable_parameterOut").bootstrapTable('getSelections', function (row) {
            return row;
        });

        var str = '';
        var value = '';
        var strVal = '';
        if (getSelectRows) {
            $("#output").val("");

            for (i = 0; i < getSelectRows.length; i++) {
                if (getSelectRows[i].objType == 1) {
                    value = '电压';
                }
                if (getSelectRows[i].objType == 2) {
                    value = 'SOC';
                }
                if (getSelectRows[i].objType == 3) {
                    value = '温度';
                }
                if (getSelectRows[i].objType == 4) {
                    value = '其他';
                }
                str += getSelectRows[i].name + "(" + value + ")" + ",";
                strVal += getSelectRows[i].esName +",";
            }
            str = str.substring(0, str.lastIndexOf(","));
            strVal = strVal.substring(0, strVal.lastIndexOf(","));
        }
        $("#dataTable_parameterOut").prop("checked", false);
        $("#modal_parameter").modal('hide');  //手动关闭
        $("#output").val(str);
        $("#output").text(str);
        $("#outputName").val(strVal);
    }
</script>